package spring.my.db.sharding.demo.config.db;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;

import javax.sql.DataSource;

//@EnableTransactionManagement
public class TransactionManagerConfig {


    @Primary
    @Bean
    public DataSourceTransactionManager transactionManager(@Qualifier("dataSource") DataSource dataSource) {
        return new DataSourceTransactionManager(dataSource);
    }


//    @Primary
//    @Bean
//    public DataSourceTransactionManager transactionManager(@Qualifier("dataSource") DataSource singleDataSource) {
//        return new DataSourceTransactionManager(singleDataSource);
//    }


//    @Bean
//    @Autowired    //自动注入 dataSource1
//    @ConditionalOnClass()
//    public PlatformTransactionManager txManager1(DataSource dataSource1) {
//        return new DataSourceTransactionManager(dataSource1);
//    }
//
//    @Bean
//    @Autowired    //自动注入 dataSource2
//    public PlatformTransactionManager txManager2(DataSource dataSource2) {
//        return new DataSourceTransactionManager(dataSource2);
//    }
}
